const App = getApp();
import util from '../../../utils/util.js';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    infoShow:true,
    searchVal:'',
    navList:[
      {title:'全部',delivery_status:'',receipt_status:''},
      {title:'待发货',delivery_status:10,receipt_status:10},
      {title:'待收货',delivery_status:20,receipt_status:10},
      {title:'已完成',delivery_status:20,receipt_status:20},
    ],
    navActive:0,
    page:1,
    list:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let {navActive}=options
    if(navActive){
      this.setData({
        navActive:navActive
      })
    }
    this.getData()
  },
  bindblur(e){
    this.setData({
      searchVal:e.detail.value
    })
},
 //搜索订单
bindconfirm(e){
  this.setData({
    searchVal:e.detail.value,
    navActive:0,
    page:1,
    list:[],
  })
  this.searchGetData()
},
//搜索获取数据
searchGetData(){
  var that=this
  App._post_form('order/orderSearch',{
    goods_name:that.data.searchVal,
},function(res){
   console.log(res)
   let list=[...that.data.list,...res.data]
    console.log(list)
    that.setData({
      list
    })
})
},
//查看物流
lookWuLiu(e){
   let order_id=e.currentTarget.dataset.ordersn
   console.log(order_id)
   wx.navigateTo({
     url: '../logistics/index?order_id='+order_id,
   })
},
// 确认收货
sureGetGoods(e){ 
  let order_id=e.currentTarget.dataset.ordersn
  var that=this
  App._post_form('user.order_integral/receipt',{
    order_id:order_id,
},function(res){
   console.log(res)
   that.setData({
    navActive:3,
    page:1,
    list:[]
  })
  that.getData()
})
},
  // 切换导航
  selectNav(e){
      let index=e.currentTarget.dataset.index
      let  navList=this.data.navList
      this.setData({
        navActive:index,
        page:1,
        list:[]
      })
      this.getData()
  },
  hiddenInfo(){
    this.setData({
      infoShow:!this.data.infoShow
    })
  },
  getData(){
    var that=this
    var page=this.data.page
    var navList=this.data.navList
    var navActive=this.data.navActive
    if(page==-1){
      wx.showToast({
        title: '暂无更多数据',
        icon:'none'
      })
      return
    }
    App._post_form('order/allIntegralOrder',{
        page:page,
        delivery_status:navList[navActive].delivery_status,
        receipt_status:navList[navActive].receipt_status,
    },function(res){
        console.log(res)
        // let {last_page,data}=res.data.list
        // if(page<last_page){
        //   page++
        // }else{
        //   page=-1
        // }
        let data=res.data
        let list=[...that.data.list,...data]
        console.log(list)
        that.setData({
          list
        })
       
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

 

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

})